import resources.Constants;

registnet.dao.Student DAOStudent;


/* [start] 	initializes gui variables */
RegistNetPropertyBundle bundle = RegistNetPropertyBundle.getInstance("/resources/registnet");
/* [end] */

/* [start]	searches for a student;
			displays the personal info of the student;
			notifies user if the student number entered found no match */
			
void searchStudent(String studentNumber){
	DAOStudent = new registnet.dao.StudentPeer().getStudent(studentNumber);
	if (DAOStudent != null){
		if (_user_type.equals(Constants.REGISTRAR)){
			showInfo();
			search_btn.focus();
		}
		else if (_user_type.equals(Constants.COLLEGE) && DAOStudent.getCurriculum().getDegreeCourse().getCollege().getCollegeCode().equals(_office)){			
			showInfo();
			search_btn.focus();
		}
		else{
			alert("Student not found");
		}
	}
	else{
		try{
			if (contents.getFirstChild() != null){
				contents.removeChild(contents.getFirstChild());
			}
			alert("Student not found");
		}catch(Exception e){ e.printStackTrace(); }
	}
}
/* [end] */



/* [start]	displays the personal info of the student */
void showInfo(){
	if (DAOStudent == null){
		alert("Student not found");
		return;
	}
	if (contents.getFirstChild() != null){
		contents.removeChild(contents.getFirstChild());
	}
	Component show_instance_form = Executions.createComponents("../../WEB-INF/macros/registration/info.zul", contents, null);
	title.setValue("Personal Info");
}
/* [end] */

/* [start]	displays the plan of coursework of the student */
void showPlanOfCoursework(){
	if (DAOStudent == null){
		alert("Student not found");
		return;
	}
	if (contents.getFirstChild() != null){
		contents.removeChild(contents.getFirstChild());
	}
	Component show_instance_form = Executions.createComponents("../../WEB-INF/macros/registration/plan_of_coursework.zul", contents, null);
	title.setValue("Plan of Coursework");
}
/* [end] */


/* [start]	displays the Ape Credit of the student */
void showAPECredit(){
	if (DAOStudent == null){
		alert("Student not found");
		return;
	}
	if (contents.getFirstChild() != null){
		contents.removeChild(contents.getFirstChild());
	}
	Component show_instance_form = Executions.createComponents("../../WEB-INF/macros/registration/ape_credit.zul", contents, null);
	title.setValue("APE Credit");
}
/* [end] */



/* [start]	displays the student records module */
void showStudentRecords(){
	String object = _student_records;
	if(!map_tab.containsKey(object)){		
		Tabs tabs = stage.getTabs();
		Tab tab = new Tab(object);
		tab.setClosable(true);
		tab.setParent(tabs);
		tab.addEventListener("onClose", new CloseTabEventListener(object));
		
		Tabpanels tabpanels = stage.getTabpanels();
		Tabpanel tabpanel = new Tabpanel();
		tabpanel.setSclass("background_light_blue");
		tabpanel.setParent(tabpanels);
		stage.setSelectedPanel(tabpanel);
		
		map_tab.put(object, tab);

		Component win = Executions.createComponents("../../WEB-INF/macros/student_records/student_records.zul", tabpanel, null);		
	}
	else
		map_tab.get(object).setSelected(true);
}
/* [end] */